package com.ruoyi.patient.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.patient.entity.CategoryListReturn;
import com.ruoyi.patient.entity.CategoryListReturnVO;
import com.ruoyi.patient.entity.ItemComboReturnVO;
import com.ruoyi.patient.entity.ItemsListReturn;
import com.ruoyi.patient.service.GetCategoryItemsListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 服务项目
 *
 * @author ZDL
 */
@RestController
@RequestMapping("/appPatient/appPatientItems")
public class ItemsController {

    @Autowired
    GetCategoryItemsListService getCategoryItemsListService;

    /**
     * 获取项目及分类列表
     *
     * @return 结果
     */
    @GetMapping("/getCategoryList")
    public AjaxResult getCategoryList()
    {
        List<CategoryListReturn> categoryItemsList = getCategoryItemsListService.getCategoryItemsList();
        AjaxResult ajax = AjaxResult.success(categoryItemsList);
        return ajax;
    }

    @GetMapping("/getCategoryListPage")
    public AjaxResult getCategoryListPage()
    {
        List<CategoryListReturnVO> categoryList = getCategoryItemsListService.getCategoryListWithPagination();
        AjaxResult ajax = AjaxResult.success(categoryList);
        return ajax;
    }

    @GetMapping("/getItemsListPage")
    public AjaxResult getItemsListPage(Long cateid, String keywords, int page, int size)
    {
        Page<ItemComboReturnVO> categoryListWithPagination = getCategoryItemsListService.getCategoryItemsListWithPagination(cateid, keywords, page, size);
        AjaxResult ajax = AjaxResult.success(categoryListWithPagination);
        return ajax;
    }

    /**
     * 搜索服务项目
     *
     * @return 结果
     */
    @GetMapping("/getItemsListBySearch")
    public AjaxResult getItemsListBySearch(String searchName, int page, int limit)
    {
        if(searchName == null || "".equals(searchName.trim()))  return AjaxResult.error("搜索内容不能为空");
        Page<ItemComboReturnVO> itemsListBySearch = getCategoryItemsListService.getItemsListBySearch(searchName, page, limit);
        AjaxResult ajax = AjaxResult.success(itemsListBySearch);
        return ajax;
    }

    /**
     * 获取项目详情
     *
     * @return 结果
     */
    @GetMapping("/getItemsDetail/{itemIds}")
    public AjaxResult getItemsDetail(@PathVariable("itemIds") Long[] itemIds)
    {
        List<ItemsListReturn> categoryItemsList = getCategoryItemsListService.getItemsDetailByItemIds(itemIds);
        AjaxResult ajax = AjaxResult.success(categoryItemsList);
        return ajax;
    }

}
